package mo.offer_special;

import mo.common.TreeNode;

public class L052 {

    private TreeNode res;

    public TreeNode increasingBST(TreeNode root) {
        if (root == null) {
            return null;
        }
        TreeNode dummy = new TreeNode();
        res = dummy;
        dfs(root);
        return dummy.right;
    }

     void dfs(TreeNode root) {
        if (root.left != null) {
            dfs(root.left);
        }

        res.right = new TreeNode(root.val);
        res = res.right;

        if (root.right != null) {
            dfs(root.right);
        }
     }

    public static void main(String[] args) {
        L052 test = new L052();
        TreeNode root = new TreeNode(5);
        root.left = new TreeNode(1);
        root.right = new TreeNode(2);
        TreeNode res = test.increasingBST(root);
        System.out.println(res);
    }

}
